from alipay import AliPay
from alipay.utils import AliPayConfig

# alipay_public_key_string = """-----BEGIN PUBLIC KEY-----
# MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEArClu+IfjaAeWzAI/A00Xyr0IeidFZDa8yHnMed7AYPCX63o5V8YQcWiyaFRFFoeGlXa6lWPvXGW
# nDhA87WLNjtfnQqP7WbHXadiCAWsyNbjbvhn0HvoqqVx0H6sh1AWdgDNkfwe+HHMFnzvKa6E3BkItULyqDku05cBOkFIM5xSTEI2L6LhmM7h06EEGr/qEBD
# XndsiZ6xbXHzfnSHzQLKClLO0n0yGIVj2hqk8+jMilgA37GDDpU4wAWGargNO20HBMo35wI7roQZOBu83mebkZeEv+32V85yglEqmMZJedyQOLJtNKvlT2U
# 4B8tyhL7hDIIjBcPFS8MyTdMpJpBwIDAQAB
# -----END PUBLIC KEY-----
# """


alipay_public_key_string = """-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqkrtl3Eb1qh00WftZrP5Tr5wExLPio+1W5XOH4rcqv38gZvINx2MwGMA9KOEuwOxnDR+8dESZ9r9SBJJdkp6znWc2mRFPLp7XtCpvODTrdxI1ZlaaMUbAhHOvpihQEkv/J+9o1cyLQsGoE3GnMkKpEEca4ig1eqoctvfI/i+nJbDk9VbqUWZLECMzi051QJP5Zd3KIVdjBNUX3W/5JXORsfombONd9C4hNG3o0cACGbGZjnF2D00UIl/ZcCaMDK9KMc2MK3mC6oloyEsWCcwh6+rwsPZUMjgF2cOVhM+/GG7RcdZ9DXf7ryQr67yajHGZm1MUygGxxHytF5tomAVawIDAQAB
-----END PUBLIC KEY-----
"""

# 秦源的
app_private_key_string = """-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEAnUunQM04GYtxFdndk3g9+iHBDOfx7QJvE1JG/ucjOck6Jd7TvbhA2P13TlU4UHhooK82ZfVtSQuEVjD1yFnCpjVFfKphadYDlv7rLafuB6fZ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qj4JRrK7xH3o81gKSNmM6n67vDIDxwrKaQKBgQCu3vUfcsbe5rD0bYXEaFuVW533qpHBUH3+/8k0qQVqF1ZW/PVdOBRJcWkSL+03Rzs+wxDumEizxlNy+OF6Q2/d3WEoq8kjGdtkGuHAAmyc9IvL/JryEG3TByYtuVcMINkbf6Q9dihWhntNEEqBLvHPkqrKczZiFAby5AvDkRqPTwKBgEdbkBhPr9EeDr0jLuw2/uFqlWQVgVxWZl8AfwHNNT+p8sz6Rla3HubR0vDpojP8CPe6+UPX1NLCeefZQ50L/TdmVU/s8ovHOYEtG0VJOCW+jMlaOZXZuMFSLuxZulgxoGpBzZmiKKzBN54zpqjucznpmgEXbb7+aYwLsLh/Dqmi
-----END RSA PRIVATE KEY-----
"""

# app_private_key_string = """-----BEGIN RSA PRIVATE KEY-----
# MIIEpAIBAAKCAQEArClu+IfjaAeWzAI/A00Xyr0IeidFZDa8yHnMed7AYPCX63o5V8YQcWiyaFRFFoeGlXa6lWPvXGWnDhA87WLNjtfnQqP7WbHXadiCAW
# syNbjbvhn0HvoqqVx0H6sh1AWdgDNkfwe+HHMFnzvKa6E3BkItULyqDku05cBOkFIM5xSTEI2L6LhmM7h06EEGr/qEBDXndsiZ6xbXHzfnSHzQLKClLO0n
# 0yGIVj2hqk8+jMilgA37GDDpU4wAWGargNO20HBMo35wI7roQZOBu83mebkZeEv+32V85yglEqmMZJedyQOLJtNKvlT2U4B8tyhL7hDIIjBcPFS8MyTdMp
# JpBwIDAQABAoIBAGadv7ZFkOdV9q0c/aAjGHZQXDgrJjJIahf4eUd+3R4q6fKChKFrvitK42RKLm/yUebOwQIAchCZyowYY6h/BtUInaBcC5p35VUCpuLf
# mSrqR5g08gxwwnL2V4T0xRISUsGyYElTPR7J9GToB4xFqH2Dfm0sNxSUTXvQN0PQlD47Sh+4YeeoCjQ1Dg1Gt/21HPWu7opNS+c7HOln4goE1AmdFIZZKo
# q6GdKooVaUz1+WcE6fxtjYggGDZuehhbeeVmb9or7vPR5LVmOXX0WWW5/XNQXr+WiCFlFyKChQdGdOZTUwTd7BQlBVhbaOxDqqFyIfqguNdLSqye0QWrXM
# b8kCgYEA7O0WZL2SRrpjneAe2OEyvojqbusk3U+xBqybVkpwKsphQd4UtMLaSTFWpEhfNAhx6qY4azZJEnbTCFmHjkWX8XA9wGuzDc4jJssMx4z4llS21u
# Mcsf+FHa5SGYYnc7PIVQWH5z3AymE7rRcYrEK7ChcGpb3qeclxQuRVRjNUUp0CgYEAugWXWKkTOTiZwvgjTD77gCCJLxKNJTr+0Xkj5m5kAQgkfctj+ylB
# j6faCJMYOJKMTIxbpoOjNI7ECpt8Ez4upOhR/kPaYNLT1yYn0EgbJVymN4NVP+Hdj8ezHGUVtAEGq9KeRMd6ZNQV4m4wf1h8r3xIAUZ9kxxxx5InKnuglv
# MCgYEAl61gvLWwQ59nztaAaRAi0GAO1VusihJOnps6BxA4puxRPz3Ru7dSz7DKavn6GPGfHD21uM1UEoIHsDzAz5A2KddVcS6BvsDNODSdxdK2AmfRddiH
# slyG9+11memMsEHUarnTu3KJTgbZkYJLxVwjKd573veqeLVB0TUkcoDB5vECgYEApsEuXAcsuWXYyKNiGQ54q/H+qBjsOEy7cxIyMXYR5a7j73RtSxA/uk
# SQupEJ7GTKqjBEVG+61PmKGawqPKHIdIHiRpmS4Kr9xedpV1fcJdD5G9h6ikqyMBqnoDOpkfQ9g7fJswRS3qIUgCehB/dNxo4VijcjiMW95VZKD9ZFLisC
# gYA5SokMX1+mAIAWeVpV79ZI0L0WRtGmMktuA7xwKd8BLy8OMAVci34Du4gJnuDWavjWxBYSNrH3VCxahJhIU7gMLBu0z2k/DEe+Gq+UQ9GYMh8uoI2/af
# iL/9HQkUdO52jo7hHlwQuUtF7lD1fSeCKmWI5CT3Edcl/SetOIcsrL6Q==
# -----END RSA PRIVATE KEY-----"""

alipay = AliPay(
    # appid="2021000122647367",
    appid = '2021000122603021',
    app_notify_url=None,  # 默认回调 url
    app_private_key_string=app_private_key_string,
    # 支付宝的公钥，验证支付宝回传消息使用，不是你自己的公钥,
    alipay_public_key_string=alipay_public_key_string,
    sign_type="RSA2",  # RSA 或者 RSA2
    debug=False,  # 默认 False
    verbose=False,  # 输出调试数据
    config=AliPayConfig(timeout=15)  # 可选，请求超时时间
)

# ret_cli =  alipay.client_api(
#   "alipay.trade.page.pay",
#   biz_content={
#     "out_trade_no": "2021000122647367",
#     "total_amount": 1.1,
#     "subject": "大床房",
#     "product_code": "FAST_INSTANT_TRADE_PAY",
#   },
#   return_url="http://127.0.0.1:9527", # this is optional
# )
# print('https://openapi.alipaydev.com/gateway.do?'+ret_cli)

 # 查询订单状态
# alipay.server_api(
#   "alipay.trade.query",
#   biz_content={
#     "out_trade_no": "202101010000"
#   }
# )
#
# # 退款
# alipay.server_api(
#   "alipay.rade.refund",
#   biz_content={
#     "out_trade_no": "202101010000",
#     "refund_amount": 12.34
#   }
# )
# #

# https://openapi.alipaydev.com/gateway.do?app_id=2021003144649040&biz_content=%7B%22out_trade_no%22%3A%2220161112%22%2C%22total_amount%22%3A0.01%2C%22subject%22%3A%22an+order%22%7D&charset=utf-8&method=alipay.trade.page.pay&return_url=https%3A%2F%2Fexample.com&sign_type=RSA2&timestamp=2023-03-20+16%3A08%3A54&version=1.0&sign=F0ORU5Yrcy87Lj4CRbNxVMKrfNnY0rtWgw719AU1pEuWuLqdMdFuCa9VBrnfWrvXDqezxQ83w6ZTOt%2BPGviDUjnumuHL8tVwSeVP%2FXDLCPGjLPG01nUhT2053YKfVJUFEcV2CCVtkh67sCCVy7VA65raWn8dHXsT9ZXsgzst3P0v%2BFBCJ3xjg4RSjtFSsLaDvSyTwjDj8rFriXMIdJYOHNyL29DpHJ7TkzayL5%2BTgedD7HIDow1KBhW9%2Bvnseoo06OLPmdG8VNoegPol3N7wA72fy6Ec5kBw0P35MWFhtSnLi8bAfnD0OxWsXE5Y6%2BZ209Is0e9uOnUY3sM7B9MqPg%3D%3D

